'use strict';

angular.module("app").service('AccountService', ['dbUtils', '$http', '$q', function (dbUtils, $http, $q) {
    return {
        getValidImgCode: function () {
            return "/validcode/img?" + new Date().getTime();
        },
        login: function (user) {
            /**/
            return dbUtils.post("/account/login", {
                username: user.username,
                password: user.password,
                verifyCode: user.verifyCode,
                rememberMe: user.rememberMe
            });
        },
        getAccount: function(success,fail){
            //return dbUtils.get("/account/get");
            jQuery.ajax({
                url: "/account/get",
                async: false,
                dataType: 'JSON',
                success:function(response){
                    success(response);
                },
                error:function(xhr,textStatus){
                    fail(xhr,textStatus);
                }
            });
        },
        sendCode: function(data){
            return dbUtils.post("/validcode/phone", data);
        },
        resetPass: function(data){
            return dbUtils.post("/account/password/forget",data);
        },
        register: function(data){
            return dbUtils.post("/account/register",data);
        },
        overview: function(data){
            return dbUtils.get("/store/overview");
        },
        modifypwd: function(data){
            return dbUtils.post("/account/modifypwd",data);
        },
        logout: function(){
            return dbUtils.get("/logout");
        }

    }
}]);